﻿using System;
using System.Windows.Forms;
using System.IO;
using Yah.Parser;
using System.Diagnostics;

namespace YahGetContent
{
    public partial class Main : Form
    {
        public Main()
        {
            InitializeComponent();
        }

        private void btnRun_Click(object sender, EventArgs e)
        {
            var timer = new Stopwatch();
            try
            {
                timer.Start();
                var getContent = new ContentExtractor(comboBoxUrl.Text);
             
                var contentNode = getContent.GetContentNode();
                
                timer.Stop();
                txtTitle.Text+="\nTime: " + timer.Elapsed.TotalSeconds.ToString();
                webBrowser1.DocumentText = "<html><body>"
                                           + getContent.GetContentHTML()
                                           + "</body></html>";
                txtTitle.Text = getContent.GetTitle() + "\n"+
                getContent.GetDataArrti(contentNode).GetVector();


            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            comboBoxUrl.SelectedIndex++;
            btnRun_Click(sender, e);
        }

        private void Main_Load(object sender, EventArgs e)
        {
            //GetContentFormUrl getContent = new GetContentFormUrl("http://www.thanhnien.com.vn/pages/20121031/phi-hanh-doan-jetstar-bi-hanh-khach-bat-lam-con-tin.aspx");
            ////HtmlAgilityPack.HtmlNode node = getContent._HTMLDocument.GetElementbyId("menu");
            //txtTitle.Text = getContent.getTitle();
            //webBrowser1.DocumentText = "<html><head></head><body>" + getContent.getContentHTML() + "</body></html>";
            var sr = new StreamReader(@"E:\DATABASE\dbGetContent\link.txt");
            while (!sr.EndOfStream)
            {
                var url = sr.ReadLine();
                if (url == null) continue;
                comboBoxUrl.Items.Add(url);
            }
            sr.Close();
            comboBoxUrl.Sorted = true;
            comboBoxUrl.SelectedIndex = 0;
        }
    }
}